package com.oa.util;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;

/**
 * 编码过滤器：
 * 负责过滤页面form表单提交的数据，把中文的编码统一为“UTF-8”,form提交过来数据的初始编码为ISO-8859-1
 * @author bond
 * @date 2015年11月11日 16:41:56
 */
@SuppressWarnings("serial")
public class SetCharacterEncodingFilter extends HttpServlet implements Filter {

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		chain.doFilter(request, response);
		
		/*HttpServletRequest request1 = (HttpServletRequest) request;
		request1.setCharacterEncoding("UTF-8");
		HttpServletResponse response1 = (HttpServletResponse) response;
		response1.setContentType("text/html;charset=utf-8");
		response1.setCharacterEncoding("UTF-8");
		chain.doFilter(request1, response1);*/
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}
}
